﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Threading.Tasks.Sources;
using System.Windows.Forms;

namespace NetworkOPSUI
{
    public partial class FrmOperatte : Form
    {


        public FrmOperatte()
        {
            InitializeComponent();

        }

        private void FrmOperatte_Load(object sender, EventArgs e)
        {


        }

        private async Task AddControlsAsync(int numberOfControls)
        {
            progressBar1.Minimum = 0;
            progressBar1.Maximum = numberOfControls;
            progressBar1.Value = 0;
            string rtspA = "rtsp://admin:abcd1234@";
            string rtspC = ":554/h265/ch1/sub/av_stream";
            for (int i = 10; i < 30; i++)
            {
                string ip = "10.153.32.";
                ip += i.ToString();
                UserControl_IPCshow userControl_IPCshow = new UserControl_IPCshow();
                userControl_IPCshow.CameraIP = ip;
                userControl_IPCshow.CameraName = "测试";
                userControl_IPCshow.RtspUrl = rtspA + ip.ToString() + rtspC;
                flowLayoutPanel1.Controls.Add(userControl_IPCshow);
                await Task.Delay(50); // 暂停50毫秒，显示新添加的控件
                progressBar1.Value++;  // 更新进度条

                //Application.DoEvents();  // 强制UI更新
                //flowLayoutPanel1.AutoScrollPosition = new Point(0, flowLayoutPanel1.Bottom); //自动滚动到最新行

            }


        }
        //private async Task AddControlsAsync(int numberOfControls)
        //{
        //    progressBar1.Minimum = 0;
        //    progressBar1.Maximum = numberOfControls;
        //    progressBar1.Value = 0;
        //    string rtspA = "rtsp://admin:abcd1234@";
        //    string rtspC = ":554/h265/ch1/sub/av_stream";
        //    for (int i = 10; i < 30; i++)
        //    {
        //        string ip = "10.153.32.";
        //        ip += i.ToString();
        //        UserControl_IPCshow userControl_IPCshow = new UserControl_IPCshow();
        //        userControl_IPCshow.CameraIP = ip;
        //        userControl_IPCshow.CameraName = "测试";
        //        userControl_IPCshow.RtspUrl = rtspA + ip.ToString() + rtspC;



        //        // 在后台线程中添加控件
        //        flowLayoutPanel1.Invoke(new Action(() =>
        //        {
        //            flowLayoutPanel1.Controls.Add(userControl_IPCshow);
        //        }));

        //        Task.Delay(50).Wait(); // 暂停50毫秒，显示新添加的控件
        //        progressBar1.Invoke(new Action(() =>
        //        {
        //            progressBar1.Value++; // 更新进度条
        //        }));

        //        //flowLayoutPanel1.Controls.Add(userControl_IPCshow);
        //        //await Task.Delay(50); // 暂停50毫秒，显示新添加的控件
        //        //progressBar1.Value++;  // 更新进度条

        //        //Application.DoEvents();  // 强制UI更新
        //        //flowLayoutPanel1.AutoScrollPosition = new Point(0, flowLayoutPanel1.Bottom); //自动滚动到最新行

        //    }


        //}
        private void FrmOperatte_Shown(object sender, EventArgs e)
        {
          AddControlsAsync(20);
        }
    }
}
